const UserService = require('../service/UserService');
const CommonService = require('../service/CommonService');
const responseData = require('../utils/responseData');

const UserController = {
	getUserInfo: async (ctx) => {
		const res = await UserService.getUserInfo(ctx.request.query);
		responseData(ctx, res);
	},
	getUserList: async (ctx) => {
		const resData = await UserService.getUserList(ctx.request.body);
		const resTotal = await CommonService.getTotal('students', ctx.request.body);
		responseData(
			ctx,
			{
				data: resData,
				total: resTotal,
			},
			'pageList',
		);
	},
	addUser: async (ctx) => {
		const res = await UserService.addUser(ctx.request.body);
		responseData(ctx, res);
	},
	updateUser: async (ctx) => {
		const res = await UserService.updateUser(ctx.request.params.id, ctx.request.body);
		responseData(ctx, res);
	},
	delUser: async (ctx) => {
		const res = await UserService.delUser(ctx.request.params.id);
		responseData(ctx, res);
	},
};

module.exports = UserController;
